/*
 * RessourceManager.hpp
 * This file is part of Dragon and Weed 2
 *
 * Copyright (C) 2011 - François Berder
 *
 * Dragon and Weed 2 is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Dragon and Weed 2 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */




#ifndef RESSOURCEMANAGER_HPP_INCLUDED
#define RESSOURCEMANAGER_HPP_INCLUDED

#include <map>
#include <boost/shared_ptr.hpp>
#include "RessourceDef.hpp"


/** \class RessourceManager
    \brief This is a base class for every specialized ressource manager.
*/
template<class T>
class RessourceManager
{
	public :

    /** \brief Default constructor
    */
	RessourceManager();

	/** \brief Default destructor
	*/
	virtual ~RessourceManager();

    /** \brief Accessor for a specific ressource
        \param resDef The ressource's definition to access
        \return A smart pointer on the ressource asked.

        \note If the ressource is not found, the ressource manager tries to load it.
        \note If the ressource couldn't be correctly loaded, this method returns a null smart pointer.
    */
	virtual boost::shared_ptr<T> ressource(RessourceDef resDef);

	/** \brief Load ressource from its definition.
        \param resDef The ressource's definition to load
        \return A boolean to check if the ressource was correctly loaded.
	*/
	virtual bool loadRessource(RessourceDef& resDef) = 0;

	/** \brief Release a specific ressource.
        \param resDef The ressource's definition to release.

        \note Because the ressource is always stored in a smart pointer, the ressource can still be used in other part of code.
	*/
	void releaseRessource(RessourceDef& resDef);

	protected :

	std::map<RessourceDef, boost::shared_ptr<T> > m_ressources;
	typedef typename std::map<RessourceDef, boost::shared_ptr<T> >::iterator RessourceIterator;

};

#include "RessourceManager.inl"

#endif
